package com.xr.miniprogram.domain.vo;

import com.xr.miniprogram.domain.MiniProgramUser;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;

import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.Date;

/**
 * 用户登录VO
 */
@Data
public class MiniProgramUserVO {

    private String code;
    /**
     * 用户唯一标识
     */
    private String token;
    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;
    @NotNull(groups = {update.class},message = "用户ID不能为空")
    private Long miniProgramUserId;
    private String encryptedData;
    private String iv;
    private Long sex;
    private Date birthday;
    private String phone;
    private Date searchBeginTime;
    private Date searchEndTime;
    private String avatarUrl;
    private String openId;
    /**
     * 昵称
     */
    private String nickName;
    private Date registerTime;
    private String roles;

    public Collection<? extends GrantedAuthority> getAuthorities()
    {
        return null;
    }
    public interface update{};

    public MiniProgramUser toMiniProgramUser(){
        MiniProgramUser miniProgramUser = new MiniProgramUser();
        miniProgramUser.setMiniProgramUserId(miniProgramUserId);
        miniProgramUser.setAvatarUrl(avatarUrl);
        miniProgramUser.setOpenId(openId);
        miniProgramUser.setNickName(nickName);
        miniProgramUser.setPhone(phone);
        miniProgramUser.setSex(sex);
        miniProgramUser.setBirthday(birthday);
        miniProgramUser.setRoles(roles);
        return miniProgramUser;
    }
    public static MiniProgramUserVO toMiniProgramUserVO(MiniProgramUser item){
        MiniProgramUserVO miniProgramUserVO = new MiniProgramUserVO();
        miniProgramUserVO.setMiniProgramUserId(item.getMiniProgramUserId());
        miniProgramUserVO.setAvatarUrl(item.getAvatarUrl());
        miniProgramUserVO.setOpenId(item.getOpenId());
        miniProgramUserVO.setNickName(item.getNickName());
        miniProgramUserVO.setPhone(item.getPhone());
        miniProgramUserVO.setSex(item.getSex());
        miniProgramUserVO.setBirthday(item.getBirthday());
        miniProgramUserVO.setRoles(item.getRoles());
        return miniProgramUserVO;
    }
}
